Skip to main content
Glama

Authenticated Next.js MCP Server

route.ts1.83 kB
import { createMcpHandler } from '@vercel/mcp-adapter' import { z } from 'zod' // Token verification function (for future use when auth is enabled) // async function verifyToken(token: string): Promise<{ valid: boolean; userId?: string }> { // // Try user-specific API key first // const { validateUserApiKey } = await import('@lib/api-keys') // const userKeyResult = validateUserApiKey(token) // if (userKeyResult.valid) { // return { valid: true, userId: userKeyResult.userId } // } // // Try OAuth token // const { oauthStorage } = await import('@lib/oauth') // const oauthToken = oauthStorage.getAccessToken(token) // if (oauthToken) { // return { valid: true } // } // // Fallback to simple bearer token // const { validateToken } = await import('@lib/auth') // const result = await validateToken(token) // return { valid: result.valid } // } const baseHandler = createMcpHandler( server => { server.tool( 'get_nextjs_docs', 'Search and retrieve Next.js documentation', { topic: z .string() .describe( 'Next.js topic to search for (e.g., "app router", "middleware", "api routes")' ), }, async ({ topic }) => { const searchUrl = `https://nextjs.org/docs?search=${encodeURIComponent(topic)}` return { content: [ { type: 'text', text: `Found Next.js documentation for: ${topic}\nSearch URL: ${searchUrl}\n\nThis will help you understand ${topic} in Next.js development.`, }, ], } } ) }, {}, { basePath: '/api', verboseLogs: true, } ) // Use base handler directly for now (auth handled by middleware) const handler = baseHandler export { handler as GET, handler as POST }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vedaterenoglu/ve-nextjs-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server